import React, { Component } from 'react'
import { Form,Input, Button , message
    ,Spin
    } from 'antd';
import '../../../init.less'
import {saveSkill} from '../../../api/request/skill'
@Form.create({name:'skill'})
class index extends Component {
    constructor(){
        super()
        this.state={
          loading:false
        }
      }
    handleSubmit=(e)=>{
       
        e.preventDefault();
        this.props.form.validateFields((err, values) => {
             
            if (!err) {
                this.setState({
                    loading:true
                })
              saveSkill(values)
                .then(res=>{
                  message.success(res.msg)
                  this.setState({
                    loading:false
                  })
                })
            }
          });
    }
    handleArticle = ()=>{
        
     
    }

    render() {
        const { getFieldDecorator,resetFields } = this.props.form;

        return (
            <Spin spinning={this.state.loading}>
            <Form  onSubmit={this.handleSubmit} className="login-form">
              <Form.Item>
                  {
                      getFieldDecorator('name',{
                        rules: [{ required: true, message: '请输入技能名称' }],
                      })(
                        <Input  className="input" placeholder="请输入技能名称"></Input> 
                      )
                  }
              </Form.Item>
              <Form.Item>
                  {
                      getFieldDecorator('max_num',{
                        rules: [{ required: true, message: '最大数量必填' }],
                      })(
                        <Input className="input" placeholder="最大数量"></Input>
                      )
                  }
              </Form.Item>
              <Form.Item>
                  {
                      getFieldDecorator('item_num',{
                        rules: [{ required: true, message: '实际数量必填' }],
                      })(
                        <Input className="input" placeholder="实际数量必填"></Input>
                      )
                  }
              </Form.Item>
            <Form.Item>
            <Button type="primary"  onClick={()=>{resetFields()}} className="login-form-button">
                   重置
                </Button>
               <Button style={{marginLeft:10}}
              htmlType="submit"
               type="primary">提交</Button>
            </Form.Item>
            </Form>
            </Spin>
        )
    }
}
export default  index